﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Windows.Forms;
using EzDeploy.Core;
using EzDeploy.Core.Controls;
using Newtonsoft.Json;

namespace EzDeploy
{
    public partial class OptionsForm : Form
    {
        private readonly Config _config ;

        public Config Config
        {
            get { return _config; }
        }

        public OptionsForm()
        {
            InitializeComponent();

            _config = ConfigHelpers.Load(Application.StartupPath);
            this.PopulateListBox();
        }

        private void Edit(object sender, EventArgs e)
        {
            StandAloneCollectionEditor.EditValue(this, _config, "Excluded");
            this.PopulateListBox();
        }

        private void PopulateListBox()
        {
            lstPattern.Items.Clear();
            foreach (var exclude in _config.Excluded)
                lstPattern.Items.Add(exclude.ToString());
        }

        private void Cancel(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
        }

        private void Save(object sender, EventArgs e)
        {
            ConfigHelpers.Save(Application.StartupPath, _config);
            this.DialogResult = DialogResult.OK;
        }
    }
}
